package com.lyl.momanapp.face.net;




import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public abstract class RetrofitUtils {

    private static final String HOST = "https://api-cn.faceplusplus.com/facepp/v3";
    public static final String SERVICE_POINTS = "http://www.xn--uu-df3cl18z.com";

    public static final String SERVICE_USER = "http://www.xn--uu-df3cl18z.com/3d/zzz/index.php";

    protected static FaceDetectApi faceDetectApi = null;
    protected static FaceSetApi facesetApi = null;
    protected static FaceApi faceApi = null;
    protected static ServiceApi serviceApi = null;
    protected static UserApi userApi = null;

    protected static OkHttpClient okHttpClient = OkhttpUtils.getOkHttpClient();

    protected static FaceDetectApi getFaceDetectApi() {
        if (null == faceDetectApi) {
            Retrofit mRetrofit = new Retrofit.Builder()
                    .baseUrl(HOST + "/")
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .client(okHttpClient)
                    .build();
            faceDetectApi = mRetrofit.create(FaceDetectApi.class);
        }
        return faceDetectApi;
    }

    protected static FaceSetApi getFaceSetApi() {
        if (null == facesetApi) {
            Retrofit mRetrofit = new Retrofit.Builder()
                    .baseUrl(HOST + "/")
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .client(okHttpClient)
                    .build();
            facesetApi = mRetrofit.create(FaceSetApi.class);
        }
        return facesetApi;
    }

    protected static FaceApi getFaceApi() {
        if (null == faceApi) {
            Retrofit mRetrofit = new Retrofit.Builder()
                    .baseUrl(HOST + "/")
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .client(okHttpClient)
                    .build();
            faceApi = mRetrofit.create(FaceApi.class);
        }
        return faceApi;
    }

    protected static ServiceApi getServiceApi() {
        if (null == serviceApi) {
            Retrofit mRetrofit = new Retrofit.Builder()
                    .baseUrl(SERVICE_POINTS + "/")
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .client(okHttpClient)
                    .build();
            serviceApi = mRetrofit.create(ServiceApi.class);
        }
        return serviceApi;
    }

    protected static UserApi getUserApi() {
        if (null == userApi) {
            Retrofit mRetrofit = new Retrofit.Builder()
                    .baseUrl(SERVICE_USER + "/")
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .client(okHttpClient)
                    .build();
            userApi = mRetrofit.create(UserApi.class);
        }
        return userApi;
    }

}